<extend name="Public/base" />
<block name="content">
<div id="content">
	<div id="content-header">
		<div id="breadcrumb">
			<a href="{:U('Index/index')}" title="首页" class="tip-bottom"><i
				class="icon-home"></i> 首页</a> <a href="{:U('Oss/index')}" class="tip-bottom">{$meta_title}</a>
	</div>
	<div class="container-fluid">
		<br/>
		<button class="btn btn-info" id="addFile">创建文件</button>
		<button class="btn btn-info" id="addDir">创建文件夹</button>
	<!-- 	<button class="btn btn-danger ajax-post" url="{:U('changeStatus?method=deleteUser')}" target-form="object_keys">删 除</button> -->
		<div class="row-fluid">
			<div class="span12">
				<div class="widget-box">
					<div class="widget-content ">
						<table class="table table-bordered table-striped with-check" id="test">
							<thead>
								<tr>
									<th>文件名</th>
									<th>大小</th>
									<th>类型</th>
									<th>创建时间</th>
									<th>操作</th>
								</tr>
							</thead>
							<tbody class="data_list">
								
								<input type="hidden" id="is_truncated" value="true"/>
								<input type="hidden" id="next_marker" value=""/>
								<input type="hidden" id="lock" value="false"/>
							</tbody>
							<tr class="loading" style="display:none">
								<td colspan="5" class="taskStatus">
									<img src="__IMG__/loading.gif"/>
								</td>
							</tr>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
	$('#addDir').click(function(){
		window.location.href='{:U("creatDir",array("bucket"=>I("bucket"),"prefix"=>I("prefix")))}';
	});
	$('#addFile').click(function(){
		window.location.href='{:U("creatFile",array("bucket"=>I("bucket"),"prefix"=>I("prefix")))}';
	});
	//导航高亮
	highlight_subnav("{:U('Oss/index')}");
});
</script>
<!-- 滚动加载 -->
<script type="text/javascript">
	$(document).ready(function(){
		//初始化加载
		loadData();
		/**
		 *@todo 删除object
		 */
		function del(){
			if(confirm('您确定要删除这个么?')){
				var key= $(this).attr('rel');
				var bucket= $(this).attr('ref');
				$.post("{:U('del')}",{key:key,bucket:bucket}).success(function(call_back){
					console.log(call_back);
					if (call_back.status==1) {
						tke_alert(call_back.info,'alert-success');
						setTimeout(function(){
		                	 if (call_back.url) {
		                         location.href=call_back.url;
		                     }else{
		                         location.reload();
		                     }
		                },1500);
					}else{
						 tke_alert(call_back.info,'alert-error');
					}
					return false;
				});
			}
			
		}
		
		function showUrl(){
			var url = $(this).attr('url');
			alert(url);
		}
	
		/**
		 *@todo 加载数据
		 */
		function loadData() {
			$('#lock').val(1);
			$('.loading').show();
			setTimeout(function(){
				var url	= "{:U('objectLists')}";
				var query	={
						bucket:"{:I('bucket')}",
						next_marker:$.trim($('#next_marker').val()),
						prefix:"{:I('prefix')}"
				}
				//请求前弹出Load图,请求后关闭.show hide;
				$.post(url,query).success(function(call_back){
			        if (call_back.status==1) {
			            if (call_back.data.list.length>0) {
			            	//设置翻页需要的参数
			            	$('#is_truncated').val(call_back.data.is_truncated);
			            	$('#next_marker').val(call_back.data.next_marker);
			            	var data =call_back.data.list;
			            	//文件夹路径
			            	var folder_url = "{:U('Oss/objectLists')}";
			            	//文件夹路径后跟参
			            	var folder_query;
			            	var folder_del_url = "{:U('del',array('prefix'=>$vo['en_prefix']))}";//删除文件夹的Url地址
			            	var file_del_url	= "{:U('del',array('objcet_key'=>$vo['objcet_key']))}";//删除object地址,也可以理解为文件
			            	var _html;
			            	for(var i in data){
			            		_html +='<tr>';
			            		//第一列
								_html += '<td style="width:40%;">';
								if(data[i].is_dir){
									folder_query ='bucket='+"{:I('bucket')}"+'&prefix='+data[i]['en_prefix'];
									folder_url = checkUrl(folder_url,folder_query);
									_html += '<img src="__IMG__/folder.png" style="margin-right:10px;"/>';
									_html += '<a href="'+folder_url+'">'+data[i]['prefix']+'</a>';
									folder_url = "{:U('Oss/objectLists')}";
									folder_query = '';
								}else{
									_html += '<input type="checkbox" value="'+data[i]['objcet_key']+'" name="object_key[]" class="object_keys"/>';
									_html += '<span style="margin-left:10px;">'+data[i]['objcet_key']+'</span>';
								}
								_html += '</td>';
								//第二列
								_html += '<td class="taskStatus">'+data[i]['size']+'</td>';
								_html += '<td class="taskStatus">'+data[i]['type']+'</td>';
								_html += '<td class="taskStatus">'+data[i]['last_modify_time']+'</td>';
								
								//暂时禁掉删除
								_html += '<td class="taskStatus">';
								if(data[i].is_dir){
									
								//	_html += '<button class="btn btn-danger" name="delDir" rel="'+data[i]['prefix']+'" ref="'+"{:I('bucket')}"+'">删 除</button>';
								}else{
								//	_html += '<button class="btn btn-danger" name="delFile" rel="'+data[i]['objcet_key']+'" ref="'+"{:I('bucket')}"+'">删 除</button>';
									_html += '<a url="'+data[i]['url']+'" href="#" title="url地址" class="file_url"><i class="icon-edit"></i> 获取地址</a>　';
								}
								_html +='</td>'; 
								_html +='</tr>';
			            	}
			            	
			            	$('.data_list').append(_html);
			            	$('button[name=delDir]').bind('click',del);
			            	$('button[name=delFile]').bind('click',del);
			            	$('.file_url').bind('click',showUrl);
			                tke_alert(call_back.info,'alert-success');
			            }else{
			            	_html += '<tr><td class="taskStatus" colspan="5">没有数据了亲</td></tr>';
			            	$('.data_list').append(_html);
			                tke_alert('没有数据了哦亲' ,'alert-success');
			            }
			        }else{
			        	//请求失败 返回错误信息
			            tke_alert(call_back.info,'alert-error');
			        }
			        $('.loading').hide();
			        $('#lock').val(0);
			        return false;
			    });
			},800);
		};  
		$(window).scroll(function(){
			if($(window).scrollTop() == $(document).height() - $(window).height()){
				if($('#is_truncated').val() && $('#next_marker').val() !='' && $('#lock').val()==0){
					loadData();
				}
			}
		}); 
	});
</script>
</block>